package com.bytedance.common.plugin.interfaces.pushmanager.util;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.os.Build;
import android.support.design.a;
import android.util.Pair;

import com.bytedance.common.utility.reflect.Reflect;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

public class ToolUtils {
    public ToolUtils() {

    }

    public static String addUrlParam(String arg5, Map arg6) {
        ArrayList v1 = new ArrayList();
        if (arg6 != null) {
            Iterator v2 = arg6.entrySet().iterator();
            while (v2.hasNext()) {
                Object v0 = v2.next();
                ((List) v1).add(new Pair(((Map.Entry) v0).getKey(), ((Map.Entry) v0).getValue()));
            }
        }

        return ToolUtils.addUrlParam(arg5, ((List) v1));
    }

    public static String addUrlParam(String arg2, List arg3) {
        StringBuilder v0 = new StringBuilder(arg2);
        if (arg2.indexOf(63) < 0) {
            v0.append("?");
        } else {
            v0.append("&");
        }

        v0.append(a.a(arg3, "UTF-8"));
        return v0.toString();
    }

    public static int areNotificationsEnabled(Context arg11) {
        int v1 = -1;
        if (arg11 == null) {
            int v0 = v1;
            return v0;
        }

        if (Build.VERSION.SDK_INT >= 24) {
            try {
                if (!((Boolean) Reflect.on(arg11.getSystemService(Context.NOTIFICATION_SERVICE)).call("areNotificationsEnabled").target).booleanValue()) {
                    return 0;
                }
                return 1;
            } catch (Exception v0_1) {
                v0_1.printStackTrace();
            }
        }

        try {
            Object v0_3 = arg11.getSystemService(Context.APP_OPS_SERVICE);
            ApplicationInfo v4 = arg11.getApplicationInfo();
            String v5 = arg11.getApplicationContext().getPackageName();
            int v4_1 = v4.uid;
            Reflect v6 = Reflect.on(v0_3);
            if (((Integer) v6.call("checkOpNoThrow", new Class[]{Integer.TYPE, Integer.TYPE, String.class},
                    new Object[]{Integer.valueOf(((Integer) v6.get("OP_POST_NOTIFICATION", new Class[]{Integer.TYPE}).target).intValue()), Integer.valueOf(v4_1), v5}).target).intValue() != 0) {
                return 0;
            }
        } catch (Throwable v0_2) {
            v0_2.printStackTrace();
            return v1;
        }

        return 1;
    }
}

